package com.demo.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

class TimeUtil{
		public static String getFirstDayOfWeek() {//获取中国式的当前周的第一天
			Calendar calendar=Calendar.getInstance();
			SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
			int no = calendar.get(Calendar.DAY_OF_WEEK);
			if(no==1){
				calendar.setTime(new Date(calendar.getTimeInMillis()-86400000));
			}
			calendar.set(Calendar.DAY_OF_WEEK,2);
			return sdf.format(calendar.getTime());
		}
		public static String getLastDayOfWeek() {//获取中国式的当前周的最后一天
			Calendar calendar=Calendar.getInstance();
			SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
			int no = calendar.get(Calendar.DAY_OF_WEEK);
			if(no!=1){
				calendar.set(Calendar.DAY_OF_WEEK,7);
				calendar.add(Calendar.DATE,1);
			}
			return sdf.format(calendar.getTime());
		}
		public static String getFirstDayOfMonth() {//获取本月的第一天
			Calendar calendar = Calendar.getInstance();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			calendar.set(Calendar.DAY_OF_MONTH, 1);
			return sdf.format(calendar.getTime());
		}
		public static String getLastDayOfMonth() {//获取本月的最后一天
			Calendar calendar = Calendar.getInstance();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
			return sdf.format(calendar.getTime());
		}
		public static String getFirstDayOfSeason() {//获取本季的第一天
			Calendar calendar = Calendar.getInstance();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			calendar.set(Calendar.MONTH,getFirstMonthOfSeason(calendar)-1);
			calendar.set(Calendar.DAY_OF_MONTH,1);
			return sdf.format(calendar.getTime());
		}
		public static String getLastDayOfSeason() {//获取本季的最后一天
			Calendar calendar = Calendar.getInstance();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			calendar.set(Calendar.MONTH,getFirstMonthOfSeason(calendar)+1);
			calendar.set(Calendar.DAY_OF_MONTH,calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
			return sdf.format(calendar.getTime());
		}

	    //获取本季的第一个月
		public static Integer getFirstMonthOfSeason(Calendar calendar) {
			Integer currentMonth = calendar.get(Calendar.MONTH) + 1;
			switch (currentMonth) {
				case 1 | 2 | 3:
					return 1;
				case 4 | 5 | 6:
					return 4;
				case 7 | 8 | 9:
					return 7;
				default:
					return 10;
			}
		}
		public static String getFirstDayOfYear() {//获取本年的第一天
			Calendar calendar = Calendar.getInstance();
			return calendar.get(Calendar.YEAR) + "-01-01";
		}
		public static String getLastDayOfYear() {//获取本年的最后一天
			Calendar calendar = Calendar.getInstance();
			return calendar.get(Calendar.YEAR) + "-12-31";
		}
	}

